n = int(input())

n1 = n // 1000
n2 = n // 100
n3 = n // 10
n4 = n 
m = 0
        
flag = True
for i in range(2,n1):
    if n1%i==0:
        flag = False
if flag == True:
    if n1>m:
        m = n1

flag = True
for i in range(2,n2):
    if n2%i==0:
        flag = False
if flag == True:
    if n2>m:
        m = n2
        
flag = True
for i in range(2,n3):
    if n3%i==0:
        flag = False
if flag == True:
    if n3>m:
        m = n3

flag = True
for i in range(2,n4):
    if n4%i==0:
        flag = False
if flag == True:
    if n4>m:
        m = n4

print(m)

